// useEffect 清除副作用
import { useEffect, useState } from "react"

function Son () {
  // 1.渲染之后开启定时器
  useEffect(() => {
    const timer = setInterval(() => {
      console.log('定时器执行中')
    }, 1000)
    return () => {
      // 清除定时器
      clearInterval(timer)
    }
  }, [])
  return (
    <div>
      this is son compnent
    </div>
  )
}
function App () {
  const [show, setShow] = useState(true)
  // useEffect(() => {
  //   console.log('副作用函数执行了！')
  // }, [show])
  return (
    <div>
      {show && <Son />}
      <button onClick={() => setShow(false)}>清除son组件</button>
    </div>
  )
}

export default App
